package com.fyzk.betzhushu.klsf;

import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betzhushu.ZhuShuBase;

import java.math.BigInteger;
import java.util.List;

/**
 * Created by miao on 2016/12/20.
 * 快乐十分任选玩法和二连组玩法注数
 */

public class KLSFSelNumZhushu extends ZhuShuBase {
    @Override
    public long betZhuShu(List<List<BallInfo>> balls) {
        int selBallNum = 0;
        for(BallInfo info : balls.get(0)){
            if(info.isSelected()){
                selBallNum++;
            }
        }

        return getZhuShu_common(selBallNum);
    }


    private int num = 2;

    public KLSFSelNumZhushu(int num) {
        this.num = num;
    }

    /**
     * 计算注数(任选n)
     */
    private long getZhuShu_common(int hong) {
        if (hong < num) {
            return 0;
        } else {
            BigInteger big = c_x_y(hong).divide(c_x_y(num)).divide(c_x_y(hong - num));
            return big.longValue();
        }
    }

    private BigInteger c_x_y(int n) {
        BigInteger big = new BigInteger("" + n);
        return (n == 0) ? new BigInteger("1") : big.multiply(c_x_y(n - 1));
    }


}
